package com.allen.study.application.api;

import com.allen.study.application.api.request.SysEmpRoleCreateRequest;
import com.allen.study.application.api.request.SysEmpRoleQueryRequest;
import com.allen.study.application.api.request.SysEmpRoleUpdateRequest;
import com.allen.study.application.api.response.SysEmpRoleQueryResponse;
import com.allen.study.application.api.response.SysEmpRoleResponse;
import com.allen.study.application.service.SysEmpRoleAppService;
import com.allen.study.common.base.ApiPageResponse;
import com.allen.study.common.base.ApiResponse;
import com.allen.study.common.base.Pagination;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 用户角色关联表接口
 *
 * @author AllenSun
 * @since 2025-04-23 20:46
 */
@RequestMapping(value = "/4.2.0/sysemprole")
@RestController
@AllArgsConstructor
@Tag(name = "用户角色关联表接口", description = "用户角色关联表接口")
public class SysEmpRoleApi {

    /**
     * 用户角色关联表应用服务
     */
    private final SysEmpRoleAppService sysEmpRoleAppService;

    /**
     * 创建用户角色关联表
     *
     * @param createRequest 用户角色关联表创建对象
     * @return 响应结果
     */
    @PostMapping
    @Operation(summary = "创建用户角色关联表", description = "创建用户角色关联表")
    public ApiResponse<Void> create(@RequestBody @Valid SysEmpRoleCreateRequest createRequest) {
        return sysEmpRoleAppService.create(createRequest);
    }

    /**
     * 根据主键删除用户角色关联表
     *
     * @param sysEmpRoleId 用户角色关联表主键
     * @return 响应结果
     */
    @DeleteMapping(value = "/{sys_emp_role_id}")
    @Operation(summary = "根据主键删除用户角色关联表", description = "根据主键删除用户角色关联表")
    public ApiResponse<Void> deleteById(@PathVariable(name = "sys_emp_role_id") String sysEmpRoleId) {
        return sysEmpRoleAppService.deleteById(sysEmpRoleId);
    }

    /**
     * 根据主键更新用户角色关联表
     *
     * @param sysEmpRoleId 用户角色关联表主键
     * @param updateRequest 用户角色关联表更新对象
     * @return 响应结果
     */
    @PutMapping(value = "/{sys_emp_role_id}")
    @Operation(summary = "根据主键更新用户角色关联表", description = "根据主键更新用户角色关联表")
    public ApiResponse<Void> updateById(@PathVariable(name = "sys_emp_role_id") String sysEmpRoleId,
            @RequestBody @Valid SysEmpRoleUpdateRequest updateRequest) {
        return sysEmpRoleAppService.updateById(sysEmpRoleId, updateRequest);
    }

    /**
     * 根据主键查询用户角色关联表详情
     *
     * @param sysEmpRoleId 用户角色关联表主键
     * @return 响应结果
     */
    @GetMapping(value = "/{sys_emp_role_id}")
    @Operation(summary = "根据主键查询用户角色关联表详情", description = "根据主键查询用户角色关联表详情")
    public ApiResponse<SysEmpRoleResponse> queryById(@PathVariable(name = "sys_emp_role_id") String sysEmpRoleId) {
        return sysEmpRoleAppService.queryById(sysEmpRoleId);
    }

    /**
     * 分页查询用户角色关联表
     *
     * @param pagination   分页
     * @param queryRequest 用户角色关联表查询对象
     * @return 响应结果
     */
    @GetMapping
    @Operation(summary = "分页查询用户角色关联表", description = "分页查询用户角色关联表")
    public ApiPageResponse<SysEmpRoleQueryResponse> query(@Valid Pagination pagination, @Valid SysEmpRoleQueryRequest queryRequest) {
        return sysEmpRoleAppService.query(pagination, queryRequest);
    }
}
